using MicroMsg.Common.Algorithm;
using MicroMsg.Common.Utils;
using System;
namespace MicroMsg.Storage
{
	public class MsgVideoStorage : MsgTransStorageProxy
	{
		public MsgTrans createMsgTrans()
		{
			MsgTrans msgTrans = new MsgTrans();
			msgTrans.nTransType = 6;
			msgTrans.strImagePath = StorageIO.getVideoPath() + msgTrans.nMsgTransID;
			base.method_1(msgTrans);
			return msgTrans;
		}
		public MsgTrans getUnCompleteDownloadingMsg()
		{
			return base.method_0((MsgTrans msgTrans_0) => msgTrans_0.nStatus != 5 && msgTrans_0.nTransType == 6);
		}
		public string getThumbnailByMsgSvrID(int nMsgSvrID)
		{
			MsgTrans byMsgSvrID = base.getByMsgSvrID(nMsgSvrID);
			if (byMsgSvrID == null)
			{
				base.dumpTable();
				return null;
			}
			return byMsgSvrID.strThumbnail;
		}
		public string getThumbnailByTransID(int nMsgTransID)
		{
			MsgTrans byMsgTransID = base.getByMsgTransID(nMsgTransID);
			if (byMsgTransID == null)
			{
				return null;
			}
			return byMsgTransID.strThumbnail;
		}
		public string getVideoFilePath(MsgTrans msgTrans_0)
		{
			return msgTrans_0.strImagePath;
		}
		public string getVideoFilePathByMsgSvrID(int nMsgSvrID)
		{
			MsgTrans byMsgSvrID = base.getByMsgSvrID(nMsgSvrID);
			if (byMsgSvrID == null)
			{
				return null;
			}
			return byMsgSvrID.strImagePath;
		}
		public void delByTransID(int nMsgTransID)
		{
			base.method_3((MsgTrans msgTrans_0) => msgTrans_0.nMsgTransID == nMsgTransID && (msgTrans_0.nTransType == 5 || msgTrans_0.nTransType == 6));
		}
		public MsgTrans updateThumbnailByMsgSvrID(int nMsgSvrID, string fromUser, string toUser, byte[] imgBuf)
		{
			if (nMsgSvrID != 0 && imgBuf != null && imgBuf.Length >= 2)
			{
				string text = StorageIO.getThumbnailPath() + "/" + Util.toHexString(MD5Core.GetHash(imgBuf)) + ".jpg";
				StorageIO.writeToFile(text, imgBuf, false);
				MsgTrans msgTrans = base.getByMsgSvrID(nMsgSvrID);
				if (msgTrans == null)
				{
					msgTrans = new MsgTrans();
					msgTrans.nMsgSvrID = nMsgSvrID;
					msgTrans.strThumbnail = text;
					msgTrans.strFromUserName = fromUser;
					msgTrans.strToUserName = toUser;
					msgTrans.nTransType = 6;
					base.method_1(msgTrans);
				}
				else
				{
					msgTrans.strThumbnail = text;
					msgTrans.strFromUserName = fromUser;
					msgTrans.strToUserName = toUser;
					base.modify(msgTrans);
				}
				return msgTrans;
			}
			return null;
		}
	}
}
